{
  Copyright 2012 Sergey Ostanin

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
}

unit Shape;

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Scene, superobject, Dispatcher;

type
  TShapeFrame = class(TFrame)
  private
    FId: TShapeId;
    FDispatcher: TDispatcher;
    FScene: TScene;
    FShape: ISuperObject;
    { private declarations }
  public
    constructor Create(const Id: TShapeId; Dispatcher: TDispatcher;
      Display: TWinControl); virtual; reintroduce;
    procedure SelectFirst;
    function UpdateShape: Boolean;

    property Dispatcher: TDispatcher read FDispatcher;
    property Id: TShapeId read FId;
    property Scene: TScene read FScene;
    property Shape: ISuperObject read FShape;
    { public declarations }
  end;
  TShapeFrameClass = class of TShapeFrame;

implementation

{$R *.lfm}

{ TShapeFrame }

constructor TShapeFrame.Create(const Id: TShapeId; Dispatcher: TDispatcher;
  Display: TWinControl);
begin
  inherited Create(nil);
  Name := Name + '_' + Id;
  FId := Id;
  FDispatcher := Dispatcher;

  FScene := Dispatcher.Scene;
  FShape := FScene.Shapes[Id];

  Parent := Display;
end;

procedure TShapeFrame.SelectFirst;
begin
  inherited;
  { nothing else to do }
end;

function TShapeFrame.UpdateShape: Boolean;
begin
  Result := FScene.Update(FId, FShape);
end;

end.

